#ifndef AER_PASSTHROUGH_HPP_
#define AER_PASSTHROUGH_HPP_

#include "aerPostEffect.hpp"


namespace aer {

// This effect is used to map a texture on the screen
// (it must be the last)
class Passthrough : public PostEffect
{
  private:
    Program m_program;
    Texture *m_pColor;
    
    
  public:
    Passthrough()
    {
      addInput( "Color", m_pColor);
    }
    
    ~Passthrough()
    {
      m_program.release();
    }    
    
    void init()
    {
      const char *fShader = AER_STRINGIFY(
        \x23 version 330\n
        
        in vec2 vTexCoord;
        layout(location = 0) out vec4 fragColor;
        uniform sampler2D uInputTex;

        void main()
        {
          fragColor = texture( uInputTex, vTexCoord);
        }
      );
      
      m_program.generate();
        m_program.addShaderSrc( Program::VERTEX_SHADER, ScreenQuad::GetVertexShader());
        m_program.addShaderSrc( Program::FRAGMENT_SHADER, fShader);
      AER_CHECK( m_program.link() );
    }
    
    void resize(const U32 width, const U32 height) {}
    
    void apply()
    {
      m_program.bind();
      m_program.setUniform( "uInputTex", 0);
      m_pColor->bind( 0u );      
        ScreenQuad::Draw();      
      m_pColor->unbind();      
      m_program.unbind();
    } 
};
  
} // aer

#endif //AER_PASSTHROUGH_HPP_
